package com.li.my_tiny_spring.beans.context;

import java.util.Map.Entry;

import com.li.my_tiny_spring.beans.definition.BeanDefinition;
import com.li.my_tiny_spring.beans.factory.AutowireCapableBeanFactory;
import com.li.my_tiny_spring.beans.reader.BeanDefinitionReader;
import com.li.my_tiny_spring.beans.reader.JsonBeanDefinitionReader;
import com.li.my_tiny_spring.util.io.ResourceLoader;

public class JsonApplicationContext extends AbstractApplicationContext{


	private String location ;
	public JsonApplicationContext(String location) {
		super(new AutowireCapableBeanFactory());
		this.location = location;
		refresh();
	}
	@Override
	protected void refresh() {
		BeanDefinitionReader reader = new JsonBeanDefinitionReader(new ResourceLoader());
		reader.loadBeanDefinitions(location);
		for (Entry<String, BeanDefinition> beanDefinitionEntry : reader.getRegistry().entrySet()) {
	        beanFactory.registerBeanDefinition(beanDefinitionEntry.getKey(), beanDefinitionEntry.getValue());
		}
		
	}

}
